package com.whfc.wxmp.api.base.service.impl;

import com.whfc.base.dto.AppWeatherLogDTO;
import com.whfc.base.dto.AppWeatherScheduleDTO;
import com.whfc.base.dto.WeatherDTO;
import com.whfc.base.entity.AppRealtimeWeather;
import com.whfc.base.service.WeatherService;
import com.whfc.common.result.ListData;
import com.whfc.fuum.dto.AppProjectDTO;
import com.whfc.fuum.service.AppProjectService;
import com.whfc.wxmp.api.base.service.WxWeatherService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 天气预报
 *
 * @author guodong_sun
 * @Description:
 * @date 2019年10月25日
 */
@Service
public class WxWeatherServiceImpl implements WxWeatherService {

    @DubboReference(interfaceClass = AppProjectService.class, version = "1.0.0")
    private AppProjectService appProjectService;

    @DubboReference(interfaceClass = WeatherService.class, version = "1.0.0")
    private WeatherService weatherService;

    @Override
    public WeatherDTO getWeather(Integer deptId) {
        AppProjectDTO projectDTO = appProjectService.getByDeptId(deptId);
        Double lng = projectDTO.getLng();
        Double lat = projectDTO.getLat();
        if (lng != null && lat != null) {
            //刷新预报天气
            return weatherService.getWeather(deptId, lng, lat);
        }
        return null;
    }
    @Override
    public WeatherDTO realtimeWeather(Integer deptId) {
        AppProjectDTO projectDTO = appProjectService.getByDeptId(deptId);
        Double lng = projectDTO.getLng();
        Double lat = projectDTO.getLat();
        if (lng != null && lat != null) {
            //刷新预报天气
            return weatherService.realtimeWeather( lng, lat);
        }
        return null;
    }

    @Override
    public ListData<AppWeatherLogDTO> getWeatherLog(Integer deptId, Date date) {
        return weatherService.getWeatherLog(deptId, date);
    }

    public List<AppWeatherScheduleDTO> getMonthWeatherSchedule(Integer deptId, Date time, Integer userId) {
        AppProjectDTO projectDTO = appProjectService.getByDeptId(deptId);
        Double lng = projectDTO.getLng();
        Double lat = projectDTO.getLat();
        return weatherService.getMonthWeatherSchedule(deptId, time,userId,lng,lat);
    }

}
